package com.hzsai.controller;

import com.hzsai.dto.UserDTO;
import com.hzsai.pojo.User;
import com.hzsai.service.MyBatisUserService;
import com.hzsai.utils.ResponseMsg;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * hzsai 2019/8/12
 * usage:
 **/
@Api(tags = "mybatis查询测试")
@RestController
@RequestMapping("/mybatisuser")
public class MyBatisUserController {

    @Autowired
    private MyBatisUserService service;

    @GetMapping("/getUser/{id}")
    public ResponseMsg getUserById(@PathVariable long id) {
        Map msg = service.getUserById(id);
        return ResponseMsg.success(msg);
    }

    @PostMapping("/insertUser")
    public ResponseMsg insertUser(@RequestBody UserDTO user) {
        return service.insertUser(user);
    }

    @GetMapping("/getPageUser/{id}/{size}")
    public ResponseMsg getPageUser(@PathVariable long id, @PathVariable long size) {
        List<User> userList = service.getPageUser(id, size);
        return ResponseMsg.success(userList);
    }

    @GetMapping("getPageUserByNameAndId/{id}/{name}")
    public ResponseMsg getUserByNameAndId(@PathVariable long id, @PathVariable String name) {
        return ResponseMsg.success(service.getUserByNameAndId(id, name));
    }
}
